package com.navi.loaddata.core.util;


import com.navi.loaddata.core.repository.impl.GreenPlumRepositoryImpl;
import java.util.concurrent.Callable;
import javax.persistence.Query;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * ExecuteSqlCallable
 *
 * @date 2018-07-14
 */
public class ExecuteSqlCallable implements Callable {

  private Logger logger = LoggerFactory.getLogger(this.getClass());

  private String sql;
  private Session session;

  public ExecuteSqlCallable(String sql, Session session) {
    this.sql = sql;
    this.session = session;

  }

  @Override
  public Integer call() throws Exception {
   return this.executeSql(sql);
  }
  public int executeSql(String sql) {
//    long startTime=System.currentTimeMillis();
      SQLQuery queryLoadStep = session.createSQLQuery(sql);
      int count = queryLoadStep.executeUpdate();
//    long endTime=System.currentTimeMillis();
//    logger.info("SQL:{}\nExecuteSql程序运行时间： {}ms", sql, endTime - startTime);
    return count;



  }

}
